#include "smsgs.h"
#include "sensor.h"
#include "SysParaConfig.h"

//extern Smsgs_vibrateSampleConfig_t vibrateSampleConfig;
//extern Smsgs_vibrateChannelConfig_t vibrateChannelConfig[];
//extern Smsgs_vibrateChannelTempConfig_t vibrateChannelTempConfig[];

const _constdef ConstDef=
{
	{'1','.','0','A'},      //软件版本
	{'1','.','0','A'},	    //硬件版本
	{'1','.','0','A'},		//协议版本
};

const uint32_t Featur_tims[] = {30,300,600,1800,3600};
const uint32_t Medium_ferq[] = {512,1024,4096,8192};
const uint32_t Medium_times[] = {300,600,3600,21600};
const uint32_t Medium_length[] = {512,1024,4096,8192};
const uint32_t High_times[] = {3600,14400,28800,43200,86400};
const uint32_t High_ferq[] = {4096,8192,16384,32768,51200};
const uint32_t High_length[] = {8192,16384,65536};
const uint32_t OverLength_times[] = {43200,86400};
const uint32_t OverLength_ferq[] = {32768,51200,65536};
const uint32_t OverLength_length[] = {131072,262144,524288,1408576};

uint32_t get_featur_times(uint8_t mode)
{
    return Featur_tims[mode];
}

uint32_t get_meduim_ferq(uint8_t mode){
    return Medium_ferq[mode];
}

uint32_t get_meduim_times(uint8_t mode){
    return Medium_times[mode];
}

uint32_t get_meduim_length(uint8_t mode){
    return Medium_length[mode];
}

uint32_t get_high_ferq(uint8_t mode){
    return High_ferq[mode];
}

uint32_t get_high_times(uint8_t mode){
    return High_times[mode];
}

uint32_t get_high_length(uint8_t mode){
    return High_length[mode];
}

uint32_t get_overlength_ferq(uint8_t mode){
    return OverLength_ferq[mode];
}

uint32_t get_overlength_times(uint8_t mode){
    return OverLength_times[mode];
}

uint32_t get_overlength_length(uint8_t mode){
    return OverLength_length[mode];
}

/*typedef struct{								
	uint8_t  UID[4];		             //UID
	uint8_t Feature_sampleTimes;         //特征值采样时间，0:30s;1:5min;2:10min:3:30min;4:60min
    uint8_t Medium_sampleEna;            //低频波形采样使能，0:disable;1:enable
    uint8_t Medium_sampleTimes;          //低频采样时间间隔，0:5min;1:10min;2:30min;3:60min;4:360min               
    uint8_t Medium_sampleFerq;           //低频采样频率，0:512hz;1:1024hz;2:4096hz;3:8192hz
    uint8_t Medium_sampleLength;         //低频采样数据长度；0:512;1:1024:2:4096;3:8192
    uint8_t High_sampleEna;              //高频采样使能，只针对Z轴，0:disable;1:enable
    uint8_t High_sampleTimes;            //高频采样间隔，0:1h;1:4h;2:8h;3:12h;4:24h
    uint8_t High_sampleFerq;             //高频采样频率，0:4096hz;1:8192hz;2:16384hz;3:32768hz;4:51200hz
    uint8_t High_sample_length;          //高频采样长度,0:8192;1:16384;2:65536
    uint8_t OverLength_sampleEna;        //超长采样使能，0:disable;1:enable;
    uint8_t OverLength_sampleTimes;      //超长采样间隔，0:12h;1:24h
    uint8_t OverLength_sampleFerq;       //超长采样频率，0:32768hz;;1:51200hz;2:65536hz
    uint8_t OverLength_sampleLength;     //超长采样数据长度，0:131072(128K);1:262144(256k);2:524288(512k);3:1048576(1M)

    uint8_t  Chl_Ena;       //通道使能
    uint16_t ACC_Zero;      //加速度零偏
    uint16_t ACC_Sens;      //加速度分辨率
    uint16_t Speed_Zero;    //速度零偏
    uint16_t Speed_Sens;    //速度分辨率
    uint16_t DISP_Zero;     //位移零偏
    uint16_t DISP_Sens;     //位移分辨率

    uint8_t TemplateEna;    //温度使能
    uint16_t TemplateZero;  //温度零偏
    uint16_t TemplateSens;  //温度分辨率
}_defaultvalue;*/

//默认初始化不启用高频及超长
const _defaultvalue DefaultVal=
{
	.UID = {0x54,0,0,0x95},
	.Feature_sampleTimes = 0,
    .Medium_sampleEna = true,
    .Medium_sampleTimes = 0,
    .Medium_sampleFerq = 0,
    .Medium_sampleLength = 0,
    .High_sampleEna = false,
    .High_sampleTimes = 0,
    .High_sampleFerq = 0,
    .High_sample_length = 0,
    .OverLength_sampleEna = false,
    .OverLength_sampleTimes = 0,
    .OverLength_sampleFerq = 0,
    .OverLength_sampleLength = 0,
    .Chl_Ena = true,
    .ACC_Zero = 0,
    .ACC_Sens = 100,
    .Speed_Zero = 0,
    .Speed_Sens = 100,
    .DISP_Zero = 0,
    .DISP_Sens = 100,
    .TemplateEna = true,
    .TemplateZero = 0,
    .TemplateSens = 100
};

static void Sysconfig_Version_Default(Smsgs_vibrateSampleConfig_t *vibrateSampleConfig)
{
    for(uint8_t i=0;i<4;i++){
        vibrateSampleConfig->hardware_type[i]=ConstDef.HwVer[i];
        vibrateSampleConfig->software_type[i]=ConstDef.SoftVer[i];
        vibrateSampleConfig->protocol_type[i]=ConstDef.ProtocolVer[i];
    }
}

void SysConfig_Default(void)
{
    Smsgs_vibrateSampleConfig_t *vibrateconfig = Sensor_getVibrateSampleConfig();
    Smsgs_vibrateChannelConfig_t *ChannelConfig = Sensor_getVibrateChannelConfig();
    Smsgs_vibrateChannelTempConfig_t *ChannelTempConfig = Sensor_getVibrateChannelTempConfig();
    for(uint8_t i = 0; i < 4; i++) {
        vibrateconfig->uid[i] = DefaultVal.UID[i];
    }
    vibrateconfig->Feature_sampleTimes = DefaultVal.Feature_sampleTimes;//特征值
    //中低频
    vibrateconfig->Medium_sampleEna = DefaultVal.Medium_sampleEna;
    vibrateconfig->Medium_sampleTimes = DefaultVal.Medium_sampleTimes;
    vibrateconfig->Medium_sampleFerq = DefaultVal.Medium_sampleFerq;
    vibrateconfig->Medium_sampleLength = DefaultVal.Medium_sampleLength;
    //高频
    vibrateconfig->High_sampleEna = DefaultVal.High_sampleEna;
    vibrateconfig->High_sampleTimes = DefaultVal.High_sampleTimes;
    vibrateconfig->High_sampleFerq = DefaultVal.High_sampleFerq;
    vibrateconfig->High_sample_length = DefaultVal.High_sample_length;
    //超长
    vibrateconfig->OverLength_sampleEna = DefaultVal.OverLength_sampleEna;
    vibrateconfig->OverLength_sampleTimes = DefaultVal.OverLength_sampleTimes;
    //写入版本
    Sysconfig_Version_Default(vibrateconfig);

    for(uint8_t i = 0; i < SENSOR_CHANNEL_NUM; i++)
    {
        ChannelConfig[i].chl = i;
        ChannelConfig[i].ena = DefaultVal.Chl_Ena;
        ChannelConfig[i].ACC_Zero = DefaultVal.ACC_Zero;
        ChannelConfig[i].ACC_Sens = DefaultVal.ACC_Sens;
        ChannelConfig[i].Speed_Zero = DefaultVal.ACC_Zero;
        ChannelConfig[i].Speed_Sens = DefaultVal.Speed_Sens;
        ChannelConfig[i].DISP_Zero = DefaultVal.DISP_Zero;
        ChannelConfig[i].DISP_Sens = DefaultVal.DISP_Sens;
    }
    //温度
    ChannelTempConfig->chl = 0;
    ChannelTempConfig->ena = DefaultVal.TemplateEna;
    ChannelTempConfig->zero = DefaultVal.TemplateZero;
    ChannelTempConfig->sens = DefaultVal.TemplateSens;
    //初次烧写上电，保存初始化参数，加入保存函数
}
